﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Web.Business
{
    public class IQueryableBal
    {

        private static IQueryableBal _dal;

        public static IQueryableBal GetInstance()
        {
            _dal = new IQueryableBal();

            return _dal;
        }

        public IEnumerable<T> GetExampleCollection<T>(T type)
        {
            // generate some random collection simulating source data
            var random = new Random();
            var collection =
            Enumerable.Repeat(0, 100).Select(
                i => new
                {
                    ClientId = random.Next(), 
                    OrderId = random.Next(), 
                    Price = random.NextDouble()
                });

            // run some linq query over it
            var queryOverCollection = from item in collection
                                      where item.ClientId % 2 == 0
                                      select new { DoublePrice = item.Price * 2.0 };
            /*
            IQueryable v = (from item in collection
                            where item.ClientId % 2 == 0
                            select new { DoublePrice = item.Price * 2.0 }).AsQueryable();
            */

            return queryOverCollection as IEnumerable<T>;
        }


    }
}